package d5_stream;

import java.util.*;
import java.util.stream.Collectors;

public class t3 {
    public static void main(String[] args) {
        List<Student> students =new ArrayList<>();
        Student s1 = new Student("文档",21,177.1);
        Student s7 = new Student("文档",21,177.1);
        Student s2 = new Student("定位",23,184.2);
        Student s3 = new Student("找出",25,151.1);
        Student s4 = new Student("大的",24,162.2);
        Student s5 = new Student("框架",45,148.9);
        Student s6 = new Student("离开",18,169.1);
        Collections.addAll(students, s1,s2,s3,s4,s5,s6,s7);

        long peo= students.stream().filter(student -> student.getHeight()>=170).count();//统计数量
        System.out.println(peo);

//        Student s = students.stream().max((o1,o2)->o1.getAge()-o2.getAge()).get();
//        System.out.println(s);

        Student s = students.stream().max((o1,o2)->Double.compare(o1.getHeight(),o2.getHeight())).get();
        System.out.println(s);

        Student st1 = students.stream().min((o1,o2)->Double.compare(o1.getHeight(),o2.getHeight())).get();//改写comparator
        System.out.println(st1);

        //收集stream,只能收集一次
        List<Student> list1= students.stream().filter(student -> student.getHeight()>=170).collect(Collectors.toList());
        System.out.println(list1);

        Set<Student> list2 = students.stream().filter(student -> student.getHeight()>=170).collect(Collectors.toSet());
        System.out.println(list2);

        Map<String,Integer> map1 = students.stream().filter(student -> student.getHeight()>=170).//收集到map
                distinct().
                collect(Collectors.toMap(a->a.getName(), a->a.getAge()));
        System.out.println(map1);

//        Object[] arr = students.stream().filter(student -> student.getHeight()>=170).toArray();
        Student[] arr = students.stream().filter(student -> student.getHeight()>=170).toArray(d->new Student[d]);
        System.out.println(Arrays.toString(arr));
    }
}
